#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
const int N = 15;
bool visit[15];
int n;
void dfs(int x, vector<int>& a) {
    if(a.size() == n) {
        for(auto& s : a) {
            cout << setw(5) << s;
        }
        cout << endl;
        return;
    }
    for(int i = 1; i <= n; i++) {
        if(!visit[i]) {
            a.push_back(i);
            visit[i] = true;
            dfs(x + 1, a);
            visit[i] = false;
            a.pop_back();
        }   
    }
}
int main() {
    cin >> n;
    vector<int> temp;
    dfs(0, temp);
    return 0;
}